package net.dengzixu.java.homework.period10;

import java.util.Scanner;

/**
 * @author Deng Zixu <admin@dengzixu.com>
 */
public class Period10Homework2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个整数: ");
        System.out.println(calc(scanner.nextInt()));
    }

    public static double calc(int n) {
        double result = 0;

        for (int i = 1; i <= n; i++) {

            if (i % 2 != 0) {
                result += 1.0 / i;
            } else {
                result -= 1.0 / i;
            }
        }

        return result;
    }
}
